﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using Unity.Collections;
public class Lighting:BaseThread
{
    const int maxVisibleLightCount = 4;
    private SRPLight _vLights;

    private CullingResults _cullingResults;
    private Shadows _shadows;
    private ShadowSettings _shadowSettings;
    
    public Lighting():base("Light Buffer")
    {
        _vLights = new SRPLight(maxVisibleLightCount, _cmd);
        _shadows = new Shadows();
    }

    public void Setup(ScriptableRenderContext context, CullingResults cR, ShadowSettings ss)
    {
        
        if(context == null)
        {
            return;
        }
        _context = context;
        _cullingResults = cR;
        _shadows.Setup(_context, _cullingResults,ss);
        BeginSample();
        SetupLights();
        EndSample();
    }
    
    private void SetupLights()
    {
        
        NativeArray<VisibleLight> _visibleLights = _cullingResults.visibleLights;
        for(int n = 0; n < _visibleLights.Length; n++)
        {
            VisibleLight vL = _visibleLights[n];
            
            _vLights.SetupLight(ref vL);
            _shadows.RenderShadow(n);
        }
        _vLights.SumbitToGpu();
        ExecuteCmd();
        _shadows.SendToGPU();
        ExecuteCmd();
        _shadows.CleanUp();


    }
}
